package com.xd.core.system.controller;

import com.xd.common.ascept.CheckSign;
import com.xd.common.ascept.LoginLogIntercept;
import com.xd.common.constant.SysConstant;
import com.xd.common.exception.XkdException;
import com.xd.common.util.XkdUtil;
import com.xd.core.debt.dto.Review;
import com.xd.core.system.dto.InsertRoleDto;
import com.xd.core.system.dto.LoginVo;
import com.xd.core.system.dto.ValidateH5TokenDto;
import com.xd.core.system.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Map;

@Slf4j
@Api(tags = "系统登录")
@RestController
@RequestMapping("/user")
public class LoginController {
    @Autowired
    private LoginService loginService;
    @CheckSign
    @ApiOperation(value = "验证码登陆", notes = "-")
    @PostMapping("/smslogin")
    public Map<String, Object> smslogin(@RequestBody LoginVo user, HttpServletRequest request) throws Exception {
        return loginService.smslogin(user, request);
    }

    @CheckSign
    @ApiOperation(value = "登陆获取token", notes = "-")
    @PostMapping("/login")
    public Map<String, Object> login(@RequestBody LoginVo user, HttpServletRequest request) throws Exception {
//        if (!XkdUtil.checkSign(user, user.getSign()))
//            throw new XkdException("签名验证失败");
        return loginService.login(user, request);
    }
    @CheckSign
    @ApiOperation(value = "异地登陆获取token", notes = "-")
    @PostMapping("/allopatricLogin")
    public Map<String, Object> allopatricLogin(@RequestBody LoginVo user, HttpServletRequest request) throws Exception {
        return loginService.allopatricLogin(user, request);
    }

    @ApiOperation("注销登录")
    @PostMapping("/logout")
    public void logout(HttpServletRequest request) {
        loginService.logout(request);
        log.info("注销成功");
    }
    @CheckSign
    @ApiOperation(value = "H5页面验证码登陆", notes = "-")
    @PostMapping("/h5Smslogin")
    public Map<String, Object> h5Smslogin(@RequestBody LoginVo user, HttpServletRequest request) throws Exception {
        return loginService.h5Smslogin(user, request);
    }

    @CheckSign
    @ApiOperation("验证H5token")
    @PostMapping("/validateH5Token")
    public void validateH5Token(@RequestBody ValidateH5TokenDto validateH5TokenDto) throws Exception {
        loginService.validateH5Token(validateH5TokenDto);

    }

}
